//
//  FKHudExtension.swift
//  FireKnowledge
//
//  Created by 杨伟毅 on 2019/4/19.
//  Copyright © 2019 wely. All rights reserved.
//

import Foundation
import MBProgressHUD

enum MBPHudType {
    case error
    case info
    case success
}

extension MBProgressHUD {
    
    class func  showOnlyText(_ title:String,_ baseView:UIView) -> Void{
        let Hud = MBProgressHUD.showAdded(to: baseView, animated: true)
        Hud.label.text = title
        Hud.mode = .text
        Hud.bezelView.layer.cornerRadius = 5
        Hud.removeFromSuperViewOnHide = true
        Hud.hide(animated: true, afterDelay: 2)
    }
    
    class func showWait(_ title:String,_ baseView:UIView) ->MBProgressHUD{
        let Hud = MBProgressHUD.showAdded(to: baseView, animated: true)
        Hud.label.text = title
        Hud.bezelView.layer.cornerRadius = 5
        Hud.removeFromSuperViewOnHide = true
       return Hud
    }
    
    func showHudAndType(_ type:MBPHudType,_ title:String,_ baseView:UIView) ->Void{
        let Hud = MBProgressHUD.showAdded(to: baseView, animated: true)
        Hud.mode = .customView
        var imageStr:String = ""
        switch type {
        case .error:
            imageStr = "error"
        case .info:
            imageStr = "info"
            break
        case .success:
            imageStr = "success"
            break
        }
        Hud.customView = UIImageView.init(image: UIImage.init(named: imageStr))
        Hud.label.text = title
        Hud.bezelView.layer.cornerRadius = 5
        Hud.removeFromSuperViewOnHide = true
        Hud.hide(animated: true, afterDelay: 2)
    }
    
}
